package cn.itcast.concurrent.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Semaphore;

/**
 * className: TestRateLimiter
 * description:
 * date: 2023/3/8 0008-14:05
 * <p>
 * project: concurrent
 * package: cn.itcast.concurrent.controller
 * email: 1085844536@qq.com
 * version:
 *
 * @author WangGuojian
 */
@RestController
public class TestRateLimiter {

    /**
     * private RateLimiter limiter = RateLimiter.create(50);
     */
    private Semaphore semaphore = new Semaphore(2);

    @GetMapping("/test")
    public String test() throws InterruptedException {
        // limiter.acquire();
        semaphore.acquire();
        try {
            return "ok";
        } finally {
            semaphore.release();
        }
    }
}
